package me.zhengjie.minbearwcs.serivce.mission.storageProcessor.locker.Floor2.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.minbearwcs.dao.storage.inf.SmallStorageDao;
import me.zhengjie.minbearwcs.dao.storage.inf.StorageDao;
import me.zhengjie.minbearwcs.entity.DTO.transfer.Tuple;
import me.zhengjie.minbearwcs.entity.PO.wcs.storage.SmallStorage;
import me.zhengjie.minbearwcs.serivce.mission.storageProcessor.locker.Floor2.Storage2FloorLocker;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class Storage2FloorLockerImpl implements Storage2FloorLocker {

    private final StorageDao storageDao;
    private final SmallStorageDao smallStorageDao;


    @Override
    public Tuple<String> lockStorage(String mediumStorage, String palletCode) {
        SmallStorage smallStorage = smallStorageDao.selectOneCanUseSmallStorageByMediunStorage(mediumStorage);
        if (smallStorage == null) {
            return Tuple.tuple("", false);
        }
        smallStorageDao.updateInboundFreezePallet(smallStorage.getId(), palletCode);

        return Tuple.tuple(smallStorage.getSmallStorageCode(),true);
    }

    @Override
    public boolean unLockStorage(String palletCode) {
        return false;
    }

    @Override
    public boolean arriveAndUnfreezeStorage(String smallStoargeCode, String palletCode) {
        return smallStorageDao.updatePalletCodeAndClearInboundFreeze(
                smallStoargeCode,
                palletCode
        );
    }
}
